package com.regvision.contacts.demo;

import java.util.List;

import com.regvision.contacts.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;


public class ChannelAdapter extends ArrayAdapter<String> {

	private int resource;
	private Context context;
	private List<String> infoList;

	public ChannelAdapter(Context context, int resource, List<String> objects) {
		super(context, resource, objects);
		// TODO Auto-generated constructor stub
		this.context = context;
		this.resource = resource;
		this.infoList = objects;
	}
	
	@Override
	public String getItem(int position) {
		// TODO Auto-generated method stub
		return infoList.get(position);
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		Holder holder;
		
		String title = (String)getItem(position);
		
		if (convertView == null) {
			
			convertView = ((LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(resource, null);
			
			holder = new Holder();
			holder.tv_title = (TextView) convertView.findViewById(R.id.tv_record_title);
			convertView.setTag(holder);
		} else {
			holder = (Holder)convertView.getTag();
		}
		
		holder.tv_title.setText(title);
		
		return convertView;
	}
	
	public void addItems(String[] arr) {
		if (arr == null) 
			return;
		
		int size = arr.length;
		for (int i = 0; i < size; i++) {
			
			String item = arr[i];

//			int index = this.infoList.indexOf(item);
//			if (index > -1) {
//				this.infoList.get(index).replace(item);
//				continue;
//			}
			
			add(item);
		}
	}

	public class Holder {
		public TextView tv_title;	
	}
}
